import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:xiongan_app_yy/pages/common/LoadBuilder.dart';
import 'package:xiongan_app_yy/provider/out_handover_details_info_provider.dart';
import 'package:xiongan_app_yy/provider/out_warehousing_provider.dart';
import 'package:xiongan_app_yy/widgets/comm/left_icon_widget.dart';

class OutHandoverDetails extends StatefulWidget {
  dynamic data;

  OutHandoverDetails(this.data);

  @override
  _OutHandoverDetailsState createState() => _OutHandoverDetailsState();
}

class _OutHandoverDetailsState extends State<OutHandoverDetails> {
  Map<String,dynamic> _data;
  bool load=false;
  Color bg=Colors.white;


  @override
  void initState() {

  }

  @override
  Widget build(BuildContext context){
  _data = Provider.of<OutHandoverDetailsInfoProvider>(context).mapData;

    return Scaffold(
      appBar: AppBar(
        leading: LeftIconWidget(icon: Icons.chevron_left, isize: 36),
        backgroundColor: Color(0XFF00A5F1),
        title: Text(
          "出库交接",
          style: TextStyle(fontSize: 18),
        ),
        elevation: 0,
        centerTitle: true,
      ),
      body: LoadBuilder(
        bgColor: bg,
    visibility: Provider.of<OutHandoverDetailsInfoProvider>(context).netStatus1,
        emptyVisibility:!Provider.of<OutHandoverDetailsInfoProvider>(context).netStatus1&&_data.length==0,
    builder:Column(
      children: <Widget>[
        Container(
          color: Colors.white,
          padding: EdgeInsets.all(10),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              RichText(
                text: TextSpan(
                  text: "入库任务单号：",
                  style: TextStyle(fontSize: 14.0, color: Color(0xff646464)),
                  children: <TextSpan>[
                    TextSpan(
                      text: "${_data["orderno"]}",
                      style:
                      TextStyle(fontSize: 14.0, color: Color(0xFF00A5F1)),
                    ),
                  ],
                ),
              ),
              Padding(
                padding: EdgeInsets.only(bottom: 6, top: 6),
                child: _Text("项目名称: ${_data["projectname"]}"),
              ),
              _Text("司机姓名: ${_data["driver"]}"),
              Padding(
                padding: EdgeInsets.only(bottom: 6, top: 6),
                child: _Text("联系方式： ${_data["phone"]??""}"),
              ),
              _Text("车牌号：${_data["carno"]}"),
              Padding(
                padding: EdgeInsets.only(bottom: 6, top: 6),
                child: _Text("拣选数量： ${_data["totalPickQuantity"]}"),
              ),
              _Text("计划出库数量： ${_data["totalPlanQuantity"]}"),
              Padding(
                padding: EdgeInsets.only(bottom: 6, top: 6),
                child: _Text("实际出库数量： ${_data["totalRealityQuantity"]}"),
              ),
              Padding(
                padding: EdgeInsets.only(bottom: 6),
                child: _Text("差异数量： ${_data["differentQuantity"]}"),
              ),
              GestureDetector(
                child: Container(
                  padding: EdgeInsets.only(top: 6, bottom: 6),
                  child: Row(
                    children: <Widget>[
                      Expanded(child: _Text("物资明细"),),
                      Center(
                        child: Container(
                          width: 6,
                          height: 12,
                          child: Image.asset("assets/images/arrow.png"),
                        ),
                      )
                    ],
                  ),
                ),
                onTap: () {
                  Navigator.pushNamed(context, '/out_handover_details_info',
                      arguments: _data['outOrderCheckDetailList']);
                },
              )
            ],
          ),
        ),
        Expanded(child: Container()),
        Offstage(
          offstage: widget.data["orderstatetypename"] == "已完成" ? true : false,
          child: Container(
              margin: EdgeInsets.only(bottom: 10),
              child: Center(
                child: FlatButton(
                    color: Colors.blue,
                    onPressed: () {
                      submitOrder(widget.data["id"]);
                    },
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(6)),
                    child: Text(
                      "确认交接",
                      style: TextStyle(color: Colors.white),
                    )),
              )),
        )
      ],
    ),),

    );
  }

  void submitOrder(String id){
    setState(() {
      bg=Colors.black26;
    });
    Provider.of<OutHandoverDetailsInfoProvider>(context).sendOrder(id).then((a) {
      if (a == true) {
        Navigator.pop(context);
        Provider.of<OutWareHousingProvider>(context).getList();
      }
    });
  }


}

class _Text extends Text {
  TextStyle style;

  _Text(String data,
      {this.style = const TextStyle(color: Color(0xff646464), fontSize: 14)})
      : super(data, style: style);
}
